import { createRouter, createWebHistory } from 'vue-router'
import homeView from '../components/homeView.vue'
// import Detail from '../views/Detail.vue'
// import User from '../views/User.vue'

const blankView = () => import('../components/blankView')
const detailView = () => import('../components/detailView')
const userView = () => import('../components/userView')
const viewError = () => import('../components/viewError')
const videoNotFound = () => import('../components/VideoNotFound')
const videoUpload = () => import('../components/videoUploadComponent/videoUpload')
const mainPage = () => import('../components/personalHomepageComponent/mainPage')

const routes = [
    { path: '/', name: 'home', component: homeView },
    { path: '/blank/:id', name: 'blank', component: blankView },
    { path: '/detail/:id', name: 'detail', component: detailView },
    { path: '/user/:id', name: 'user', component: userView },
    { path: '/viewError', name: 'viewError', component: viewError },
    { path: '/videoNotFound', name: 'videoNotFound', component: videoNotFound },
    { path: '/videoUpload', name: 'videoUpload', component: videoUpload },
    { path: '/mainPage/:id', name: 'mainPage', component: mainPage },
]

const router = createRouter({
    history: createWebHistory(),
    routes
})

//路由守卫//这个方法需要放在new Vue之前，不然按F5刷新页面不会调用这个方法
router.beforeEach((to,from,next) => {

    //未找到路由的情况
    if (!to.matched.length){
        // const storeMenus = localStorage.getItem("userInfo")//判断是否有登录
        // if (storeMenus){
        //     next("/viewError")
        // }else {
        //     //调回登录页面
        //     next("/")
        // }
        next("/viewError")
    }
    //其他情况放行
    next()
})

export default router
